$file1 = "/data1/bsi/bioinf_int/s106381.borawork/data_HTHGU/MayoGAP/mayogap_emerge/clean/new_mayogap_emerge_clean.tfam";
open BUFF1, "$file1" or die "Can't open $file1 : $!";
$file2 = "/data1/bsi/bioinf_int/s106381.borawork/data_HTHGU/MayoGAP/mayogap_emerge/clean/new_mayogap_emerge_clean.tped";
open BUFF2, "$file2" or die "Can't open $file2 : $!";
$n = 1;
open(WRBUFF,">/data1/bsi/bioinf_int/s106381.borawork/data_HTHGU/MayoGAP/mayogap_emerge/clean/emerge_input.txt");
while($line = <BUFF1>)
{	
	chomp $line;
	#$line =~ s/\t//g;
	$line =~ s/\n//g;
	$line =~ s/\r//g;
	@array = split(" ",$line);
	$hash{$n} = $array[1];		
	$n++;
}

while($line = <BUFF2>)
{
        chomp $line;
        #$line =~ s/\t//g;
        $line =~ s/\n//g;
        $line =~ s/\r//g;
        @array = split(" ",$line);
	$i =4;
	$j = 1;
        while($i< @array)
	{
		$temp1 = $array[$i];
		$i++;
		$temp2 = $array[$i];
		$i++;
		print  WRBUFF $hash{$j}."\t".$array[1]."\t".$temp1."\t".$temp2."\n";			
		$j++;	
	}
        
}


